package data;

import org.jboss.netty.buffer.ChannelBuffer;

import system.Config;
import util.ChannelBufferUtil;

import com.mongodb.BasicDBObject;

public class DBPlayer {
	public BasicDBObject db;
	
	public int getUnreadCount() {
		if (!db.containsField("unreadCount"))
			return 0;
		return db.getInt("unreadCount");
	}
	
	public void setUnreadCount(int v) {
		db.put("unreadCount", v);
	}
	
	public int getLevel() {
		return db.getInt("level");
	}
	
	public String getName() {
		return db.getString("name");
	}
	
	public void setName(String v) {
		db.put("name", v);
	}
	
	public int getSex() {
		return db.getInt("sex");
	}
	
	public String getGUID() {
		return db.getString("guid");
	}
	
	public int getPvpScore() {
		return db.getInt("pvpScore");
	}
	
	public void setScore(int v) {
		db.put("pvpScore", v);
	}	
	
	public int getPvpWinCount() {
		return db.getInt("pvpWinCount");
	}
	
	public void setPvPWinCount(int v) {
		db.put("pvpWinCount", v);
	}
	
	public int getPvpCount() {
		return db.getInt("pvpCount");
	}
	
	public void setPvPCount(int v) {
		db.put("pvpCount", v);
	}
	
	public int getPVPLevel() {
		return Config.getPVPLevel(getPvpScore());
	}
	
	public long getActiveTime() {
		if (db.containsField("lastActiveTime")) 
			return db.getLong("lastActiveTime");
		return 0;
	}
	
	public int getWinPercent() {
		return (int)((float)getPvpWinCount()*100/getPvpCount());	
	}
	
	public long getLastEnterPVPTime() {
		return db.getLong("lastEnterPVPTime");
	}
	
	public void setLastEnterPVPTime(long v) {
		db.put("lastEnterPVPTime", v);
	}
	
	public int getLastChallangeDay() {
		if (!db.containsField("lastChallangeDay"))
			return 0;
		return db.getInt("lastChallangeDay");
	}
	
	public int getTodayChallengeCount() {
		if (!db.containsField("todayChallangeCount"))
			return 0;
		return db.getInt("todayChallangeCount");
	}
	
	public void setLastChallangeDay(int v) {
		db.put("lastChallangeDay", v);
	}
	
	public void setTodayChallengeCount(int v) {
		db.put("todayChallangeCount", v);
	}
	
	public void serialize(ChannelBuffer buf) {
		ChannelBufferUtil.writeString(buf, getGUID());
		buf.writeByte(getSex());
		ChannelBufferUtil.writeString(buf, getName());
		buf.writeInt(getLevel());
		buf.writeInt(getPvpScore());
	}
	
	
	
	public void save() {
		
	}
}
